import 'package:baselib/utils/log_util.dart';
import 'package:flutter/material.dart';
import 'package:framelib/base/base_view_model.dart';
import 'package:module_business/comm/service/comm_service.dart';
import 'package:module_business/my/service/my_service.dart';

class MyViewModel extends BaseViewModel with WidgetsBindingObserver {
  MyService myService = MyService();
  CommService commService = CommService();

  @override
  void onInit() {
    WidgetsBinding.instance.addObserver(this);
    super.onInit();
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    WidgetsBinding.instance.removeObserver(this);
    super.onClose();
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);
    switch (state) {
      case AppLifecycleState.inactive:
        //inactive:用户可见，但不可响应用户操作
        LogUtil.d('didChangeAppLifecycleState-->state=inactive');
        break;
      case AppLifecycleState.paused:
        //paused:已经暂停了，用户不可见、不可操作
        LogUtil.d('didChangeAppLifecycleState-->state=paused');
        break;
      case AppLifecycleState.resumed:
        LogUtil.d('didChangeAppLifecycleState-->state=resumed');
        //从后台返回到前台
        break;
      case AppLifecycleState.detached:
        //detached：当前页面即将退出
        LogUtil.d('didChangeAppLifecycleState-->state=detached');
        break;
      case AppLifecycleState.hidden:
        break;
    }
  }
}
